We create a 2D array with classic declaration:int array[3][4]
And we create an array with malloc(): marray[3][4]
In the first case we find that array=array[0]
BUT in the second marray does not equal to marray[0]
The second appears to me logical but the first not!
In the second case we make the marray with this code:
Code:int rows = 10; int cols = 10; int *data; int **marray; int i,j; /* assume malloc always succeeds */ data = malloc(rows * cols * sizeof(*data)); marray = malloc(rows * sizeof(*marray)); for (i = 0; i < rows; ++i) { marray[i] = &data[i * cols]; }